package org.gtug.vg;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class MainActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Button helloBtn = (Button) findViewById(R.id.helloBtn);
		final EditText name = ((EditText) findViewById(R.id.nameTxt));
		helloBtn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Toast.makeText(MainActivity.this, "Hello " + name.getText(), Toast.LENGTH_SHORT).show();
			}
		});
		Button helloBtnDialog = (Button) findViewById(R.id.helloBtnDialog);
		helloBtnDialog.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
				alertDialog.setTitle("Hello");
				alertDialog.setMessage("Hello " + name.getText());
				alertDialog.setButton("Thank you", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialogInterface, int i) {
						alertDialog.dismiss();
					}
				});
				alertDialog.show();
			}
		});
		CheckBox showImgCkb = (CheckBox) findViewById(R.id.showImgCkb);
		showImgCkb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
				findViewById(R.id.image).setVisibility(checked ? View.VISIBLE : View.GONE);
			}
		});
		Button clearFieldBtn = (Button) findViewById(R.id.clearNameBtn);
		clearFieldBtn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				name.setText("");
			}
		});
	}
}
